import {RouteRecordRaw,Router} from "vue-router";

function filterAsyncRoute(asyncRoute: RouteRecordRaw[], routes: string[]) {
    return asyncRoute.filter((item: any) => {
        if (routes.includes(item.meta.permission)) {
            if (item.children && item.children.length > 0) {
                item.children = filterAsyncRoute(item.children, routes)
            }
            return true
        }
    })
}

function removeDynamicRouter(router:Router){
    router.getRoutes().forEach(route => {
        // 这里还需要条件判断哪些是静态路由不需要移除
        let whiteArr = ['/login', '/home', '/404', '/:pathMatch(.*)*', '/']
        if (!whiteArr.includes(route.path)) {
            router.removeRoute(route.name);
        }
    });
}

export {
    filterAsyncRoute,
    removeDynamicRouter
}
